<?php

class GuestbookController extends AppController {
    var $uses = array("GuestbookEntry");
    var $paginate = array(
            'limit' => 20,
            'order' => array(
                'GuestbookEntry.timestamp' => 'desc',
                'GuestbookEntry.id' => 'desc'
            )
        );
    
    public function index() {
        $this->set("data", array_reverse($this->paginate('GuestbookEntry')));
    }
    
    public function admin_index() {
        $this->set("data", array_reverse($this->paginate('GuestbookEntry')));
    }

    public function create() {
        $this->title = "Wpisz się";

        if (!empty($this->data)) {
            $this->data['timestamp'] = time();
            if ($this->GuestbookEntry->save($this->data)) {
                $this->Session->setFlash('Zapisano.');
                $this->redirect(array('action' => 'index'));
            }
        }
    }
    
    public function admin_delete($id) {
        $this->title = "Usuwanie wpisu";

        if ($this->GuestbookEntry->delete($id)) {
            $this->Session->setFlash('Usunięto.');
            $this->redirect(array('action' => 'admin_index'));
        }
    }
}
?>
